<template>
	<view class="userconfig">
		<view class="inputrow">
			<view class="inputrow__label">名称:</view>
			<AGInput :value="meInfo.UserName" placeholder="请输入名称" :readonly="true" />
		</view>
		<view class="inputrow">
			<view class="inputrow__label">账号:</view>
			<AGInput :value="meInfo.Telephone" placeholder="请输入账号" :readonly="true" />
		</view>
		<view class="inputrow">
			<view class="inputrow__label">上岗证:</view>
			<AGInput :value="meInfo.IdCard" placeholder="请输入上岗证" :readonly="true" />
		</view>
		<view class="inputrow">
			<view class="inputrow__label">服务网点:</view>
			<AGInput :value="meInfo.ServiceSite" placeholder="请输入服务网点" :readonly="true" />
		</view>
		<view class="inputrow">
			<view class="inputrow__label">服务区域:</view>
			<AGInput :value="meInfo.ServiceZone" placeholder="请输入服务区域" :readonly="true" />
		</view>
		<view class="ag-divider"></view>
		<view class="inputrow">
			<AGInput :value="meInfo.HomeAddress" label="住址" placeholder="请输入住址" @change="homeaddressChange" />
		</view>
		<button class="cu-btn block lg primary" @click="saveHomeAddress">保存</button>
	</view>
</template>
<script>
	import AGInput from '../../components/AGInput';
	export default {
		components: {
			AGInput
		},
		data() {
			return {
				meInfo: {}
			}
		},
		onLoad(e) {

		},
		onShow(e) {
			let pages = getCurrentPages();
			let prevPageData = pages[pages.length - 2].data;
			if (prevPageData.hasOwnProperty("meInfo")) {
				this.meInfo = prevPageData.meInfo;
				console.log(this.meInfo)
			}
		},
		methods: {
			homeaddressChange(e) {
				this.meInfo.HomeAddress = e;
				console.log(this.meInfo.HomeAddress);
			},
			saveHomeAddress(e) {

				if (this.meInfo.HomeAddress)
					this.updateHomeAddress();
				else
				{
					uni.showToast({
						title: "住址不能为空",
						icon:"none"
					})
				}
			
			},
			async updateHomeAddress() {
				uni.showLoading({
					title: "保存中...",
					mask: true
				})
				let uPhone = this.UserInfo.mobile;
				let token = this.UserInfo.RetId;

				let saveFlag = await this.meService.saveUserAddress(uPhone, this.meInfo.HomeAddress, token);
				if(saveFlag.RetBool){
					uni.hideLoading();
					uni.showToast({
						title: "保存成功",
						icon:"none"
					})
				}else{
					uni.hideLoading();
				}
				console.log(saveFlag);
				
			}
		}

	}
</script>
<style lang="scss">
	page {
		background-color: white;
	}

	.userconfig {
		padding: 20rpx 40rpx;

		.inputrow {
			display: flex;
			flex-direction: row;
			align-items: center;
			margin-top: -10rpx;

			&__label {
				width: 120rpx;
				font-size: 24rpx;
				color: #808080;
			}

			.ag-input {
				flex: 1;
			}

			a-g-input {
				flex: 1;
			}
		}

		.ag-divider {
			margin: 10rpx 0;
		}
	}
</style>
